// 环形链表 II   找出环形链表的起点

var detectCycle = function (head) {
  let slow = head, fast = head
  while (fast !== null && fast.next !== null) {
    slow = slow.next
    fast = fast.next.next
    if (slow === fast) {
      break
    }
  }

  if (fast === null || fast.next === null) {
    // fast 遇到空指针说明没有环
    return null
  }

  // 重新指向头结点
  slow = head
  while (slow !== fast) {
    // 快慢指针同步前进，相交点就是环起点
    slow = slow.next
    fast = fast.next
  }
  return slow

};